//
//  MainViewController.m
//  WaterStreet
//
//  Created by 재효 조 on 12. 2. 13..
//  Copyright (c) 2012년 가족. All rights reserved.
//

#import "MainViewController.h"

@implementation MainViewController

@synthesize managedObjectContext = _managedObjectContext;
@synthesize testImg = _testImg;
@synthesize btnTestImg = _btnTestImg;

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle


- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
}

- (void)viewDidUnload
{
    [self setTestImg:nil];
    [self setBtnTestImg:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    
    UIImage *mainImage = [[[ImageEffect alloc] init] convertBlackAndWhite:[UIImage imageNamed:@"main.jpg"]];
    
    CALayer * main = [CALayer layer];
    main.contents = (id)mainImage.CGImage;
    main.bounds = CGRectMake(0, 0, mainImage.size.width, mainImage.size.height);
    main.position = CGPointMake(self.view.bounds.size.width / 2,
                                 mainImage.size.height / 2);

    
    [self.view.layer insertSublayer:main atIndex:0];
    
    //[self.view.layer addSublayer:main];

    
    
    [main addAnimation:[[[ImageAnimations alloc] init] moveBackgoundReverceSlide:main] forKey:@"position"];
     
}

- (void)viewWillDisappear:(BOOL)animated
{
	[super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
	[super viewDidDisappear:animated];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
    } else {
        return YES;
    }
}

- (IBAction)btnTestImgAni:(id)sender {
    [UIView beginAnimations:nil context:nil];
    {
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        [UIView setAnimationDuration:3.0];
        [UIView setAnimationDelegate:self];
        [UIView setAnimationDidStopSelector:@selector(didEndAnimation)];
        [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:_testImg cache:YES];
        [_testImg setImage:[UIImage imageNamed:@"WS2_photo2.jpg"] ];
    }
    [UIView commitAnimations];
}
-(void) didEndAnimation
{
//    [_testImg removeFromSuperview]; 
}

@end
